/**
 * @file module_keyboard.h
 * @author Blues Jiang
 * @brief
 * @version 0.1
 * @date 2022-03-26
 *
 * @copyright Copyright (c) 2022
 *
 */

#ifndef __MODULE_KEYBOARD_H__
#define __MODULE_KEYBOARD_H__

#include <rtthread.h>
#include <Blues_keymap.h>
#include <pin_dev_cfg.h>

enum encoder_state
{
    ENCODER_NO_ACTION = 0,
    ENCODER_ACTION_CW,
    ENCODER_ACTION_CCW
};

const rt_base_t ROW_PIN_INDEX[MATRIX_ROWS] =
{
    PIN_ROW1,
    PIN_ROW2,
    PIN_ROW3,
    PIN_ROW4,
    PIN_ROW5,
};

const rt_base_t COLUMN_PIN_INDEX[MATRIX_COLS] =
{
    PIN_COLUMN1,
    PIN_COLUMN2,
    PIN_COLUMN3,
    PIN_COLUMN4,
    PIN_COLUMN5,
    PIN_COLUMN6,
};

const rt_base_t ENCODER_PIN_INDEX[ENCODER_NUM * 2] =
{
    PIN_ENCODER1A,
    PIN_ENCODER1B,
    PIN_ENCODER2A,
    PIN_ENCODER2B,
    PIN_ENCODER3A,
    PIN_ENCODER3B,
};

void update_keycode_format(rt_uint8_t* msg, rt_uint8_t keycode, rt_uint8_t* limit); //Length is static 8 byte
rt_base_t if_need_update(rt_uint8_t* msg, rt_uint8_t length);
void clear_keycode_msg(rt_uint8_t* msg, rt_uint8_t length, rt_uint8_t* limit); //Length is static 8 byte

// rt_base_t sync_encoder_state(rt_base_t* laststate, rt_base_t* nextaction, rt_base_t encoder_a_pin, rt_base_t encoder_b_pin);
rt_base_t sync_encoder_state(rt_base_t* nextaction, rt_base_t encoder_a_pin, rt_base_t encoder_b_pin);


#endif /* __MODULE_KEYBOARD_H__ */
